#include "stdafx.h"
#include <boost/test/auto_unit_test.hpp>
#include "bmock.hpp"


typedef int (*g_ptr)(int,char*);

struct test_mock_class2 {
	test_mock_class2(int x,int *y);
	int f(int x,int *y);
	int f(int x,int *y) const;
	void g(int x,int *y);
	void cg(int x,int *y) const;
	void l(int y, g_ptr k);
	static int b (int x,char*y);
	~test_mock_class2();
};

struct test_method_pointer2 {
	test_method_pointer2();
	~test_method_pointer2();
};

test_mock_class2::test_mock_class2(int x,int *y) {
	MOCK_VOID(2, (IN(x), OUT(y)));
}
int test_mock_class2::f(int x,int *y) {
	MOCK(2, (IN(x), OUT(y)));
	return 1;
}
int test_mock_class2::f(int x,int *y) const{
	MOCK(2, (IN(x), OUT(y)));
	return 1;
}
void test_mock_class2::g(int x,int *y) {
	MOCK_VOID(2, (IN(x), OUT(y)));
}
test_mock_class2::~test_mock_class2() {
	MOCK_VOID(0,());
}
void test_mock_class2::l(int y, g_ptr x) {
	MOCK_VOID(2,(IN(y),IN_PTR(x)));
}
int test_mock_class2::b(int x,char*y) {
	MOCK(2, (IN(x), IN(y)));
	return 1;
}


struct test_mock_class_fixture2 {
	test_mock_class_fixture2()
		:x(10)
		,exp_y(11)
		,y(0)
		,ptr(NULL)
	{		
		BMOCK_CREATE_MOCK(*);
	}

	const int        x;
	int              exp_y;
	int              y;
	test_mock_class2 *ptr;
	test_mock_class_fixture2 func_test_coverage(const test_mock_class_fixture2 & x){
		return *this=x;
	}
private:
	test_mock_class_fixture2 &operator =(const test_mock_class_fixture2 &) {
		return *this;
	}
};

BMOCK_TEST(test_mock_class_fixture2,test_contructor_destructor) {
	BMOCK_EXPECT(ptr = new test_mock_class2(x,&exp_y));
	BMOCK_EXPECT(delete ptr);
	BMOCK_REPLAY;
	BOOST_CHECK_NO_THROW({ test_mock_class2 tst(x,&y);});
	BMOCK_VERIFY;
	BOOST_CHECK_EQUAL(exp_y,y);
}

BMOCK_TEST(test_mock_class_fixture2,test_contructor_only) {
	test_mock_class2 *ptr1 = 0;

	BMOCK_EXPECT(ptr = new test_mock_class2(x,&exp_y));
	BMOCK_REPLAY;
	BOOST_CHECK_NO_THROW(ptr1 = new test_mock_class2(x,&y));
	BMOCK_VERIFY;
	BOOST_CHECK_EQUAL(exp_y,y);
	//tierDown
	BMOCK_EXPECT(delete ptr);
	BMOCK_REPLAY;
	delete ptr1;
	BMOCK_VERIFY;
}

BMOCK_TEST(test_mock_class_fixture2,test_destructor_only) {
	//setUp
	test_mock_class2 *ptr1 = 0;

	BMOCK_EXPECT(ptr = new test_mock_class2(x,&exp_y));
	BMOCK_REPLAY;
	BOOST_CHECK_NO_THROW(ptr1 = new test_mock_class2(x,&y));
	BMOCK_VERIFY;
	//test
	BMOCK_EXPECT(delete ptr);
	BMOCK_REPLAY;
	BOOST_CHECK_NO_THROW(delete ptr1;);
	BMOCK_VERIFY;
}

BMOCK_TEST(test_mock_class_fixture2,test_coverage2) 
{
	test_mock_class_fixture2 x;
	test_mock_class_fixture2 y;
	BOOST_CHECK_NO_THROW(x.func_test_coverage(y));
}

